package com.wyzz.hr.util.output;

import java.awt.Color;

public class FieldOperate {

	public FieldOperate() {
		colWidth = 15;
		groupOrder = 0;
	}

	public FieldOperate(String fieldName, String showName, String dataType,
			String format) {
		colWidth = 15;
		groupOrder = 0;
		setFieldName(fieldName);
		setShowName(showName);
		setDataType(dataType);
		setFormat(format);
	}

	public FieldOperate(String fieldName, String showName, String dataType,
			String format, int colWidth) {
		this.colWidth = 15;
		groupOrder = 0;
		setFieldName(fieldName);
		setShowName(showName);
		setDataType(dataType);
		setFormat(format);
		setColWidth(colWidth);
	}

	public FieldOperate(String fieldName, String showName, String dataType,
			String format, String statisticMethod, int colWidth, int groupOrder) {
		this.colWidth = 15;
		this.groupOrder = 0;
		setFieldName(fieldName);
		setShowName(showName);
		setDataType(dataType);
		setFormat(format);
		setStatisticMethod(statisticMethod);
		setColWidth(colWidth);
		setGroupOrder(groupOrder);
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		if (format != null && format.length() < 1)
			format = null;
		this.format = format;
	}

	public String getStatisticMethod() {
		return statisticMethod;
	}

	public void setStatisticMethod(String statisticMethod) {
		if (statisticMethod == null || statisticMethod.length() < 1) {
			this.statisticMethod = null;
			statisticDataType = null;
			statisticFormat = null;
		} else {
			this.statisticMethod = statisticMethod;
			if (this.statisticMethod.compareTo("count") == 0) {
				statisticDataType = "integer";
				statisticFormat = null;
			} else {
				statisticDataType = dataType;
				statisticFormat = format;
			}
		}
	}

	public String getShowName() {
		return showName;
	}

	public void setShowName(String showName) {
		this.showName = showName;
		int place = showName.lastIndexOf("-");
		if (place > 0) {
			normalName = showName.substring(0, place);
			statisitcName = showName.substring(place + 1);
		} else {
			normalName = showName;
			statisitcName = showName;
		}
	}

	public String getNormalName() {
		return normalName;
	}

	public String getStatisitcName() {
		return statisitcName;
	}

	public int getColWidth() {
		return colWidth;
	}

	public void setColWidth(int colWidth) {
		if (colWidth > 0)
			this.colWidth = colWidth;
	}

	public String getDataType() {
		return dataType;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	public Color getColBgColor() {
		return colBgColor;
	}

	public void setColBgColor(Color colBgColor) {
		this.colBgColor = colBgColor;
	}

	public int getGroupOrder() {
		return groupOrder;
	}

	public void setGroupOrder(int groupOrder) {
		if (Math.abs(groupOrder) > 2)
			groupOrder = 0;
		this.groupOrder = groupOrder;
	}

	public String getStatisticDataType() {
		return statisticDataType;
	}

	public String getStatisticFormat() {
		return statisticFormat;
	}

	private String fieldName;
	private String showName;
	private String normalName;
	private String statisitcName;
	private String dataType;
	private String format;
	private String statisticMethod;
	private int colWidth;
	private int groupOrder;
	private Color colBgColor;
	private String statisticDataType;
	private String statisticFormat;
	public final String NAME_SEPERATOR = "-";
}
